<template>
	<view class="favorite">
		<scroll-view lower-threshold="50" scroll-y="true" @scrolltolower="lower" class="solutioncontent">
			<showItem v-for="item in solutionList" :key="item.id" :solution="item" @setFavorite="setFavorite"></showItem>
		</scroll-view>
	</view>
</template>

<script>
import { getFavoriteSolutionList } from '../../api/favorite/favorite';
export default {
	data() {
		return {
			solutionList:[],
			total:[],
			timer:null,
			pageNum:1
		};
	},
	created() {
		console.log("获取收藏方案")
		this.getSolutionList()
	},
	methods: {
		async getSolutionList() {
			const { total, rows } = await getFavoriteSolutionList(this.pageNum);
			this.solutionList=this.solutionList.concat(rows)
			this.total=total
		},
		setFavorite(favorite, solutionid) {
			this.solutionList.forEach((item) => {
				if (item.id === solutionid) {
					item.favorite = favorite;
				}
			});
		},
		lower: function (e) {
			if (this.timer != null ||this.total<=this.solutionList.length) return;
			this.timer = setTimeout(() => {
				this.pageNum+=1
				this.getSolutionList()
				clearTimeout(this.timer)
				this.timer=null
			}, 500);
		},
	}
};
</script>

<style lang="less" scoped>
	.favorite{
		height: 100vh;
		.solutioncontent{
			height: 100%;
		}
	}
</style>
